package com.bdth.bdthiss.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.bdth.bdthiss.entity.ArticleCategory;
import com.bdth.bdthiss.entity.Customer;
import com.bdth.bdthiss.entity.Seller;
import com.bdth.bdthiss.service.ArticleCategoryService;
import com.bdth.bdthiss.service.SellerService;
import com.bdth.bdthiss.vo.MessageResult;
import com.bdth.bdthiss.vo.PageVo;
import com.bdth.bdthiss.vo.Pagination;
import com.bdth.bdthiss.vo.RuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * <p>
 * 竞价分类信息 前端控制器
 * </p>
 *
 * @author LGP
 * @since 2019-08-21
 */
@Controller
@RequestMapping("/compete")
public class ArticleCategoryController {
    @Autowired
    private ArticleCategoryService articleCategoryService;

    @RequestMapping(value = "category")
    public String index() {
        return "articleCategory/index";
    }

    @RequestMapping(value = "category/list")
    @ResponseBody
    public PageVo<ArticleCategory> getPageList(Pagination<ArticleCategory> pagination, @RequestParam(required = false) String name){
        Page<ArticleCategory> items = articleCategoryService.listPages(pagination, name);
        PageVo<ArticleCategory> pageVo = new PageVo<>(items.getRecords(),items.getTotal());
        return pageVo;
    }

    @RequestMapping(value = "category/search")
    public String search() {
        return "articleCategory/search";
    }

    @RequestMapping(value = "category/form")
    public String form() {
        return "articleCategory/form";
    }

    @RequestMapping(value = "category/save")
    @ResponseBody
    public MessageResult save(ArticleCategory param){
        param.setHash(0);
        articleCategoryService.insert(param);
        return MessageResult.getSuccess("添加数据成功");
    }

    @RequestMapping(value = "category/update")
    @ResponseBody
    public MessageResult update(ArticleCategory param){
        param.setHash(0);
        articleCategoryService.updateById(param);
        return MessageResult.getSuccess("修改数据成功");
    }

    @RequestMapping(value = "category/delete")
    @ResponseBody
    public MessageResult delete(@RequestParam Integer ids){
        articleCategoryService.deleteById(ids);
        return MessageResult.getSuccess("数据已删除");
    }
}

